package com.wyp168.juc;

/**
 * @ClassName YieldDemo001
 * @Description TODO
 * @Author wyp168
 * @Date 2022/7/8 14:03
 */
public class YieldDemo001 implements Runnable{
    public YieldDemo001() {
        Thread thread = new Thread(this);
        thread.start();
    }

    @Override
    public void run() {
        for (int i = 0; i < 5; i++) {
            if (i % 5 == 0) {
                System.out.println(Thread.currentThread() + " yield Cpu");
                //让出CPU资源
//                Thread.yield();
            }
        }
        System.out.println(Thread.currentThread() + "  over...");

    }

    public static void main(String[] args) {
        new YieldDemo001();
        new YieldDemo001();
        new YieldDemo001();
    }
}
